package com.dwk.rabbitMQ4;


import com.dwk.utils.RabbitMqUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;

import java.util.Scanner;

/**
 * 将队列和消息进行持久化
 */
public class Task03 {
    private static final String TASK_QUEUE_NAME="durable_ack_queue";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        //开启发布确认
        channel.confirmSelect();
        boolean durable=true;
        //将队列持久化
        channel.queueDeclare(TASK_QUEUE_NAME,durable,false,false,null);
        //从控制台接收信息代码
        Scanner scanner=new Scanner(System.in);
        while (scanner.hasNext()){
            String message=scanner.next();
            //设置生产者发送消息为持久化消息（要求保存在磁盘上）（MessageProperties.PERSISTENT_TEXT_PLAIN）
            channel.basicPublish("",TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN,message.getBytes("utf-8"));
            System.out.println("消息发送完毕");
        }

    }
}
